﻿using MengLin.OOP.DesignPattern.CompsitePattern.CompanyManager.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.CompsitePattern.CompanyManager.Implements
{
    /// <summary>
    /// 具体公司
    /// </summary>
    public class ConcreteCompany : AbstractCompany
    {
        private List<AbstractCompany> children = new List<AbstractCompany>();

        public ConcreteCompany(string name) : base(name)
        {

        }

        public override void Add(AbstractCompany c)
        {
            children.Add(c);
        }

        public override void Remove(AbstractCompany c)
        {
            children.Remove(c);
        }

        public override void Display(int depth)
        {
            Console.WriteLine(new String('-', depth) + _name);
            foreach (AbstractCompany component in children)
            {
                component.Display(depth + 2);
            }
        }

        //履行职责
        public override void LineOfDuty()
        {
            foreach (AbstractCompany component in children)
            {
                component.LineOfDuty();
            }
        }
    }
}
